#include <bits/stdc++.h>
using namespace std;
const int N = 15;

int n, ans, cnt;
bool r[N], c[N], dia[2 * N], udia[2 * N];
bool st[N][N];

void dfs(int x, int y)
{
	if(y > n)
	{
		y %= n + 1;
		x ++;
	}
	if(x > n)
	{
		if(cnt == n)
		{
			for(int i = 1;i <= n;i ++)
			{
				for(int j = 1;j <= n;j ++)
				{
					if(st[i][j]) 
					{
						cout << j << " ";
						break;
					}
				}
			}
			cout << endl;
		}
		ans ++;
		return;
	}

	if(!r[x] && !c[y] && !dia[y - x + n] && !udia[y + x])
	{
		r[x] = c[y] = dia[y - x + n] = udia[y + x] = true;
		st[x][y] = true;
		y ++;
		dfs(x, y);
	}
}

int main()
{
	cin >> n;
	dfs(1, 1);
	cout << ans << endl;
	return 0;
}